<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\MusicType;
use Illuminate\Http\Request;

class MusicTypeController extends Controller
{
    public function index()
    {

        $musicTypes = MusicType::orderBy("music_type_order", "asc")->get();
        return view("admin.musicType.index", [
            "musicTypes" => $musicTypes,
            "pageName" => "音乐分类列表",
        ]);
    }

    public function create()
    {
        return view("admin.musicType.create", [
            "pageName" => "添加音乐分类",
        ]);
    }

    public function save(Request $request)
    {
        $musicType = new MusicType();
        $musicType->music_type_name = $request->post("music_type_name");
        $musicType->music_type_order = $request->post("music_type_order");
        $musicType->save();
        return redirect()->route("adminMusicTypeIndex");

    }

    public function delete(Request $request)
    {
        $id = $request->input("id");
        MusicType::destroy($id);
        return redirect()->route("adminMusicTypeIndex");

    }

    public function edit(Request $request)
    {
        $id = $request->input("id");
        $musicType = MusicType::find($id);

        return view("admin.musicType.edit", [
            "musicType" => $musicType,
            "pageName" => "编辑音乐分类",
        ]);
    }
    public function update(Request $request)
    {
        $id = $request->input("id");
        $musicType = MusicType::find($id);
        $musicType->music_type_name = $request->post("music_type_name");
        $musicType->music_type_order = $request->post("music_type_order");
        $musicType->save();
        return redirect()->route("adminMusicTypeIndex");

    }
}
